<?php
namespace my;
/**
 * 组建前端html类
 * @author xls
 */
class Html{
    
    /**
     * 组建后端ajax的table列表
     * @param unknown $list    列表数据
     * @param unknown $arr     格式化列的key值
     * @return  列表 tbody html
     */
    public static function buildTable($list, $arr){
        if ( !$list ) 
            return '<tr><td colspan="'.count( $arr ).'"><h1>没有数据</h1></td></tr>';
        
        $tbody = "";
        foreach ( $list as $val ) {
            $tbody .= "<tr>";
            foreach ($arr as $k) {
                $tbody .= "<td>" . $val[$k] . "</td>";
            }
            $tbody .= "</tr>";
        }
        return $tbody;
    }
    
    /**
     * 组件分页html
     * @param unknown $data 分页数据的原始数据
     * @return 分页html
     */
    public static function buildPage( $data = [] ){
        $temp = "";
        if( !empty($data) ){
            $data['total']          = $data['total'] ? $data['total'] : 0;
            $data['total_page_num'] = $data['total_page_num'] ? $data['total_page_num'] : 0;
            $temp .='<div class="dataTables_info">共有数据：<b>'.$data['total'].'</b>条, <b>'.$data['total_page_num'].'</b>页</div>';
            
            
            $temp .= "<div class='dataTables_paginate paging_simple_numbers'>";
        
            //首页
            if (isset($data['first']) && !empty($data['first'])) {
                $temp .= '<a class="paginate_button" href="javascript:void(0)" onclick="com_search(' . $data['first'] . ')">首页</a>';
            }
            //上一页
            if (isset($data['pre']) && !empty($data['pre'])) {
                $temp .= '<a class="paginate_button" href="javascript:void(0)" onclick="com_search(' . $data['pre'] . ')">上一页</a>';
            }
            //数字目录
            foreach ($data['list'] as $val) {
                $is_cur = $val == $data['cur'] ? true : false;
                if($is_cur){
                    $temp .= '<span><a class="paginate_button current" href="javascript:void(0)" onclick="com_search(' . $val . ')">' . $val . '</a></span>';
                }else{
                    $temp .= '<a class="paginate_button" href="javascript:void(0)" onclick="com_search(' . $val . ')">' . $val . '</a>';
                }
            }
        
            //下一页
            if (isset($data['next']) && !empty($data['next'])) {
                $temp .= '<a class="paginate_button" href="javascript:void(0)" onclick="com_search(' . $data['next'] . ')">下一页</a>';
            }
            
            //尾页
            if (isset($data['last']) && !empty($data['last'])) {
                $temp .= '<a class="paginate_button" href="javascript:void(0)" onclick="com_search(' . $data['last'] . ')">尾页</a>';
            }
            
            $temp .= "</div>";
        }
        return $temp;
    }
    
    /**
     * 组建用户下拉
     * @param unknown $username
     */
    public static function buildUserSelect( $username ){
        $html  = "";
        $html .= "<select onchange='search(this)'>";
        $html .= "<option _href='' value='100all'>{$username}</option>";
        $html .= "<option _href='".url("@admin/Trade/lists","username={$username}")."' value='{$username}-方案列表'>->方案列表</option>";
        $html .= "<option _href='".url("@admin/TradeUser/lists","username={$username}")."' value='{$username}-购彩记录'>->购彩记录</option>";
        $html .= "<option _href='".url("@admin/Recharge/lists","username={$username}")."' value='{$username}-充值记录'>->充值记录</option>";
        $html .= "<option _href='".url("@admin/Withdraw/lists","username={$username}")."' value='{$username}-提现记录'>->提现记录</option>";
        $html .= "<option _href='".url("@admin/Handmoney/lists","username={$username}")."' value='{$username}-人工处理'>->人工处理</option>";
        $html .= "<option _href='".url("@admin/Bill/lists","username={$username}")."' value='{$username}-账单流水'>->账单流水</option>";
        $html .= "</select>"; 
        return $html;
    }
}